<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>创建新方法</title>
</head>

<body>
    <!-- 原型是JavaScript全局构造函数。它可以构建新Javascript对象的属性和方法。 -->
    <p id="demo">单击按钮创建一个数组,调用 ucase（）方法, 并显示结果。</p>
    <button onclick="myFunction()">点我</button>
    <script>
        Array.prototype.myUcase = function () {
            for (i = 0; i < this.length; i++) {
                this[i] = this[i].toUpperCase();
            }
        }
        function myFunction() {
            var fruits = ["Banana", "Orange", "Apple", "Mango"];
            fruits.myUcase();
            var x = document.getElementById("demo");
            x.innerHTML = fruits;
        }
    </script>
</body>

</html>